<%@page import="util.enviaEmail"%>
<%
Connection conn = null;
try {
	conn = new Conexao().getConexao();
} catch (Exception e) {
	new enviaEmail().enviar(e);
	out.print("falhaConexao");
	return;
}
%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="dao.OSDao"%>
<%@page import="bean.OSBean"%>
<%@page import="java.util.List"%>
<%@page import="conexao.Conexao"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="css/blue/style.css" />
<script src="js/jquery.tablesorter.min.js"></script>
<script>
	$(function() {

		$("#tbodyEnviadas tr td img").click(function() {
			if ($(this).attr("title") != "finalizar") {
				var id = $(this).parent().parent().attr("id");
				var nome = $(this).parent().attr("id");
				
				$("#descricao").val("\n" + $("#descricao"+id).html() + "\n\n" + $("#comentario"+id).html());
				$("#descricao").scrollTop(999999);
				$("#descricao").show();
				$("#fontMsn").html("");
				$("#idOs").val(id);
				$("#nomeCliente").html("OS nº: "+id +"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cliente: "+ nome);
			} else {
				$("#dialogConfirmaId").val($(this).parent().parent().attr("id"));
				$("#dialogConfirm").dialog("open");
			}

		});

	});
</script>
</head>
<body>
	
			<table class="tablesorter">
			<tbody id="tbodyEnviadas">
				<%
				Integer sessaoIdFuncao = (Integer) session.getAttribute("idfuncao");
					ArrayList<OSBean> designerOS = new ArrayList<OSBean>();
					SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm");
					OSBean os = new OSBean();
					os.setIdEmpresa((Integer) session.getAttribute("idempresa"));
					
					if(sessaoIdFuncao == 2){
						designerOS = new OSDao().getListaOS(conn, "('designer')",
							(Integer) request.getSession().getAttribute("id"));
					}
					if(sessaoIdFuncao == 3){
						designerOS = new OSDao().getListaSituacaoOS(conn, "imprimir", os);
					}
					if(sessaoIdFuncao == 4){
						designerOS = new OSDao().getListaSituacaoOS(conn, "producao", os);
					}
					if(sessaoIdFuncao == 5){
						designerOS = new OSDao().getListaSituacaoOS(conn, "entregar", os);
					}
					if (!designerOS.isEmpty()) {
						for (int n = 0; n < designerOS.size(); n++) {
							String data = "";
							if(designerOS.get(n).getSituacao().equals("designer")){
								data = df.format(designerOS.get(n).getDataDesigner());
							}
							if(designerOS.get(n).getSituacao().equals("imprimir")){
								data = df.format(designerOS.get(n).getDataImprimir());
							}
							if(designerOS.get(n).getSituacao().equals("producao")){
								data = df.format(designerOS.get(n).getDataProducao());
							}
							if(designerOS.get(n).getSituacao().equals("entregar")){
								data = df.format(designerOS.get(n).getDataEntrega());
							}
				%>
				<tr id="<%=designerOS.get(n).getId()%>"
					<%if (designerOS.get(n).getUrgente() == 1) {%> style="color: red;"
					<%}%>>
					<td width="27"><%=designerOS.get(n).getId()%></td>
					<td><%=designerOS.get(n).getNomeCliente()%></td>
					<td width="85" align="center"><%=data%></td>
					<td align="center" width="57" id="<%=designerOS.get(n).getNomeCliente()%>"><img src="imagens/magnifier-zoom.png" style="cursor: pointer;" title="Visualizar Descrição e Comentário"> 
					<img src="imagens/tick-button.png" style="cursor: pointer;" title="finalizar">
					<div id="descricao<%=designerOS.get(n).getId()%>" style="display: none;"><%=designerOS.get(n).getDescricao()%></div>
					<div id="comentario<%=designerOS.get(n).getId()%>" style="display: none;"><%if(designerOS.get(n).getComentario() != null){%><%=designerOS.get(n).getComentario()%><%}%></div>
					</td>
				</tr>
				<%
					}
					} else {
				%>
				<tr>
					<td colspan="3">Nenhuma OS enviada</td>
				</tr>
				<%
					}
					conn.close();
				%>
			</tbody>
		</table>
</body>
</html>